<?php
require_once("init.php");
$arr = array("openStatistics","clickTrack");
$str = '';

$flag = rand(0,1);
$timeStamps = time();
$sql = "select id, address, addressId, type from ".$arr[$flag]." where verifyFlag = 0 group by address limit 0,10";
$result = $GLOBALS['db']->dbfetchAll($sql);
if(empty($result)){
	exit;
}
foreach($emailLimitTypeArr as $k=>$v){
	$emailTypeArr[$k] = $v;
}
foreach($emailThirdTypeArr as $k=>$v){
	$emailTypeArr[$k] = $v;
}
if(strpos($arr[$flag],"open")!==false){
	$tableFlag = "open";
}else if(strpos($arr[$flag],"click")!==false){
	$tableFlag = "click";
}else{
	$tableFlag = "others";
}
foreach($result as $key=>$value){
    if(array_key_exists($value['type'],$emailTypeArr)){
		$sql = "select id from ".$emailTypeArr[$value['type']]." where address = '".$value['address']."'";
		$result = $GLOBALS['db']->dbGetRow($sql);
		if($result['id']!==$value['addressId']){
			$sql = "insert into badEmail(email,emailId,type,tableFlag,timeStamps) values('".$value['address']."',".$value['addressId'].",".$value['type'].", '".$tableFlag."', '".$timeStamps."')";
			$GLOBALS['db']->dbquery($sql);
		}
	}else{
			$sql = "insert into badEmail(email,emailId,type,tableFlag,timeStamps) values('".$value['address']."',".$value['addressId'].",".$value['type'].", '".$tableFlag."', '".$timeStamps."')";
			$GLOBALS['db']->dbquery($sql);
	}
	$str = $str.",".$value['id'];
	$str = trim($str, ",");
	$sql = "update ".$arr[$flag]." set verifyFlag = 1 where id in(".$str.")";
	$GLOBALS['db']->dbquery($sql);
}
?>